
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
SET(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build,
options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release
RelWithDebInfo MinSizeRel.")

PROJECT(FASTFEM)

SET(FASTFEM_VERSION_MAJOR 0)
SET(FASTFEM_VERSION_MINOR 1)
SET(FASTFEM_VERSION_PATCH 0)
SET(FASTFEM_VERSION ${FASTFEM_VERSION_MAJOR}.${FASTFEM_VERSION_MINOR}.${FASTFEM_VERSION_PATCH})

INCLUDE(CMakeExportBuildSettings)
ENABLE_TESTING()

# Find the modules necessary for confguration
SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})

SET(LIB_DIR "lib")
SET(FASTFEM_BIN_DIR bin)
SET(FASTFEM_LIB_DIR ${LIB_DIR})
SET(FASTFEM_INCLUDE_DIR include/fastfem)
SET(FASTFEM_SHARE_DIR share/fastfem)
SET(FASTFEM_LIBRARY_TYPE "STATIC" CACHE STRING
    "Specify static or shared build type for library.")
MARK_AS_ADVANCED(FASTFEM_LIBRARY_TYPE)

# Set up RPATH
SET(CMAKE_SKIP_BUILD_RPATH  FALSE)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_DIR}")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
SET(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${LIB_DIR}")
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
  "${CMAKE_INSTALL_PREFIX}/${LIB_DIR}" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
  SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_DIR}")
ENDIF("${isSystemDir}" STREQUAL "-1")

SET(FASTFEM_USE_OPENMP OFF CACHE BOOL
"Use OpenMP parallelization to accelerate the polylib evaluation." )
IF ( ${FASTFEM_USE_OPENMP} STREQUAL "ON" )
	FIND_PACKAGE(OpenMP)
ENDIF ( ${FASTFEM_USE_OPENMP} STREQUAL "ON" )

SET(FASTFEM_FULL_DEBUG  OFF CACHE BOOL
    "Enable Full Debugging.")
MARK_AS_ADVANCED(FASTFEM_FULL_DEBUG)

IF (${CMAKE_COMPILER_IS_GNUCXX})
    SET(FASTFEM_ENABLE_PROFILE OFF CACHE BOOL
        "Compiles FASTFEM with the -pg compiler flag")
    MARK_AS_ADVANCED(FASTFEM_ENABLE_PROFILE)
ENDIF (${CMAKE_COMPILER_IS_GNUCXX})

IF( APPLE )
    SET(FASTFEM_USE_ACCELERATE_FRAMEWORK ON CACHE BOOL
        "Use the Mac Accelerate Framework for BLAS and Lapack support." )
ELSE(APPLE)
    IF( UNIX )
        SET(FASTFEM_USE_SYSTEM_BLAS_LAPACK ON CACHE BOOL
            "Use the system provided blas and lapack libraries")
    ENDIF(UNIX)
ENDIF(APPLE)

SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
SET(CMAKE_CXX_FLAGS "-fPIC -DPIC")

SET(COMPILER_NAME ${CMAKE_C_COMPILER} CACHE STRING
    "Debugging data: Compiler name.")

# Include Nektar++ common macros
INCLUDE (fastfem_common)

# Set up include directories
INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/include/fadbad++ ${CMAKE_SOURCE_DIR}/polylib )


SET(PolyLibHeaders
	./polylib/polylib.hh
	./polylib/polylib_templated.hh
)

SET(PolyLibSources
	./polylib/polylib.cc
	./polylib/polylib_templated.cc
)

SOURCE_GROUP("Polylib Headers" FILES ${PolyLibHeaders})
SOURCE_GROUP("Polylib Sources" FILES ${PolyLibSources})

SET(LibFASTFEMHeaders
	${PolyLibHeaders}
)

SET(LibFASTFEMSources
	${PolyLibSources}
)

# Recurse into the "Hello" and "Demo" subdirectories. This does not actually
# cause another cmake executable to run. The same process will walk through
# the project's entire directory structure.
ADD_SUBDIRECTORY (polylib)
ADD_SUBDIRECTORY (src)
ADD_SUBDIRECTORY (tests)

SET(CMAKE_BUILD_TYPE Debug)
IF (NOT CMAKE_BUILD_TYPE)
	MESSAGE(STATUS "No build type selected, default to Debug")
	SET(CMAKE_BUILD_TYPE "Debug")
endif()

